home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / AlgoWaveTableList.c < prev    next >
Text File  |  1994-12-03  |  28KB  |  853 lines

  1. /* AlgoWaveTableList.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "AlgoWaveTableList.h"
  31. #include "StringList.h"
  32. #include "Array.h"
  33. #include "Memory.h"
  34. #include "Alert.h"
  35. #include "DataMunging.h"
  36. #include "AlgoWaveTableObject.h"
  37. #include "BufferedFileInput.h"
  38. #include "BufferedFileOutput.h"
  39. #include "Files.h"
  40. #include "Scrap.h"
  41.  
  42.  
  43. struct AlgoWaveTableListRec
  44.     {
  45.         StringListRec*                    List;
  46.         struct CodeCenterRec*        CodeCenter;
  47.         struct MainWindowRec*        MainWindow;
  48.         ArrayRec*                                AlgoWaveTableArray;
  49.         MyBoolean                                AlgoWaveTableListChanged;
  50.     };
  51.  
  52.  
  53. #define MAGICSCRAPSTRING ("\xff\x00\x1f\xfe AlgoWaveTableObjectScrap")
  54.  
  55.  
  56. AlgoWaveTableListRec*    NewAlgoWaveTableList(struct MainWindowRec* MainWindow,
  57.                                             struct CodeCenterRec* CodeCenter, WinType* ScreenID,
  58.                                             OrdType XLoc, OrdType YLoc, OrdType Width, OrdType Height)
  59.     {
  60.         AlgoWaveTableListRec*    AlgoWaveTableList;
  61.  
  62.         AlgoWaveTableList = (AlgoWaveTableListRec*)AllocPtrCanFail(sizeof(AlgoWaveTableListRec),
  63.             "AlgoWaveTableListRec");
  64.         if (AlgoWaveTableList == NIL)
  65.             {
  66.              FailurePoint1:
  67.                 return NIL;
  68.             }
  69.         AlgoWaveTableList->AlgoWaveTableArray = NewArray();
  70.         if (AlgoWaveTableList->AlgoWaveTableArray == NIL)
  71.             {
  72.              FailurePoint2:
  73.                 ReleasePtr((char*)AlgoWaveTableList);
  74.                 goto FailurePoint1;
  75.             }
  76.         AlgoWaveTableList->List = NewStringList(ScreenID,XLoc,YLoc,Width,Height,
  77.             GetScreenFont(),9,StringListDontAllowMultipleSelection,"Algorithmic Wave Tables");
  78.         if (AlgoWaveTableList->List == NIL)
  79.             {
  80.              FailurePoint3:
  81.                 DisposeArray(AlgoWaveTableList->AlgoWaveTableArray);
  82.                 goto FailurePoint2;
  83.             }
  84.         AlgoWaveTableList->CodeCenter = CodeCenter;
  85.         AlgoWaveTableList->MainWindow = MainWindow;
  86.         AlgoWaveTableList->AlgoWaveTableListChanged = False;
  87.         return AlgoWaveTableList;
  88.     }
  89.  
  90.  
  91. /* delete the algorithmic wave table list and all of the wave tables it contains */
  92. void                                DisposeAlgoWaveTableList(AlgoWaveTableListRec* AlgoWaveTableList)
  93.     {
  94.         long                            Scan;
  95.         long                            Limit;
  96.  
  97.         CheckPtrExistence(AlgoWaveTableList);
  98.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  99.         for (Scan = 0; Scan < Limit; Scan += 1)
  100.             {
  101.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  102.  
  103.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  104.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  105.                 DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  106.             }
  107.         DisposeArray(AlgoWaveTableList->AlgoWaveTableArray);
  108.         DisposeStringList(AlgoWaveTableList->List);
  109.         ReleasePtr((char*)AlgoWaveTableList);
  110.     }
  111.  
  112.  
  113. /* change the location of the algorithmic wave table list in the window */
  114. void                                SetAlgoWaveTableListLocation(AlgoWaveTableListRec* AlgoWaveTableList,
  115.                                             OrdType XLoc, OrdType YLoc, OrdType Width, OrdType Height)
  116.     {
  117.         CheckPtrExistence(AlgoWaveTableList);
  118.         SetStringListLoc(AlgoWaveTableList->List,XLoc,YLoc,Width,Height);
  119.     }
  120.  
  121.  
  122. /* redraw the list */
  123. void                                AlgoWaveTableListRedraw(AlgoWaveTableListRec* AlgoWaveTableList)
  124.     {
  125.         CheckPtrExistence(AlgoWaveTableList);
  126.         RedrawStringList(AlgoWaveTableList->List);
  127.     }
  128.  
  129.  
  130. /* see if the specified coordinates falls inside the wave table list rectangle */
  131. MyBoolean                        AlgoWaveTableListHitTest(AlgoWaveTableListRec* AlgoWaveTableList,
  132.                                             OrdType XLoc, OrdType YLoc)
  133.     {
  134.         CheckPtrExistence(AlgoWaveTableList);
  135.         return StringListHitTest(AlgoWaveTableList->List,XLoc,YLoc);
  136.     }
  137.  
  138.  
  139. /* handle a mouse down event for the algorithmic wave table list */
  140. void                                AlgoWaveTableListDoMouseDown(AlgoWaveTableListRec* AlgoWaveTableList,
  141.                                             OrdType XLoc, OrdType YLoc, ModifierFlags Modifiers)
  142.     {
  143.         CheckPtrExistence(AlgoWaveTableList);
  144.         if (StringListMouseDown(AlgoWaveTableList->List,XLoc,YLoc,Modifiers))
  145.             {
  146.                 /* if it returns true, then it was a double click */
  147.                 AlgoWaveTableListOpenSelection(AlgoWaveTableList);
  148.             }
  149.     }
  150.  
  151.  
  152. /* called when the window becomes active */
  153. void                                AlgoWaveTableListBecomeActive(AlgoWaveTableListRec* AlgoWaveTableList)
  154.     {
  155.         CheckPtrExistence(AlgoWaveTableList);
  156.         EnableStringList(AlgoWaveTableList->List);
  157.     }
  158.  
  159.  
  160. /* called when the window becomes inactive */
  161. void                                AlgoWaveTableListBecomeInactive(AlgoWaveTableListRec* AlgoWaveTableList)
  162.     {
  163.         CheckPtrExistence(AlgoWaveTableList);
  164.         DisableStringList(AlgoWaveTableList->List);
  165.     }
  166.  
  167.  
  168. /* called when a selection is made in another list, so that this list */
  169. /* is deselected */
  170. void                                AlgoWaveTableListDeselect(AlgoWaveTableListRec* AlgoWaveTableList)
  171.     {
  172.         CheckPtrExistence(AlgoWaveTableList);
  173.         DeselectAllStringListElements(AlgoWaveTableList->List);
  174.     }
  175.  
  176.  
  177. /* check to see if there is a selection in this list */
  178. MyBoolean                        AlgoWaveTableListIsThereSelection(AlgoWaveTableListRec* AlgoWaveTableList)
  179.     {
  180.         CheckPtrExistence(AlgoWaveTableList);
  181.         return (GetStringListHowManySelectedItems(AlgoWaveTableList->List) > 0);
  182.     }
  183.  
  184.  
  185. /* check to see if any of the algorithmic wave tables contained in this list need */
  186. /* to be saved */
  187. MyBoolean                        DoesAlgoWaveTableListNeedToBeSaved(AlgoWaveTableListRec* AlgoWaveTableList)
  188.     {
  189.         long                            Scan;
  190.         long                            Limit;
  191.         MyBoolean                    Flag;
  192.  
  193.         CheckPtrExistence(AlgoWaveTableList);
  194.         Flag = AlgoWaveTableList->AlgoWaveTableListChanged;
  195.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  196.         for (Scan = 0; (Scan < Limit) && !Flag; Scan += 1)
  197.             {
  198.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  199.  
  200.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  201.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  202.                 if (HasAlgoWaveTableObjectBeenModified(AlgoWaveTableTemp))
  203.                     {
  204.                         Flag = True;
  205.                     }
  206.             }
  207.         return Flag;
  208.     }
  209.  
  210.  
  211. /* open an edit window for the selected algorithmic wave table */
  212. void                                AlgoWaveTableListOpenSelection(AlgoWaveTableListRec* AlgoWaveTableList)
  213.     {
  214.         ArrayRec*                    ListOfSelections;
  215.  
  216.         CheckPtrExistence(AlgoWaveTableList);
  217.         ListOfSelections = GetListOfSelectedItems(AlgoWaveTableList->List);
  218.         if (ListOfSelections != NIL)
  219.             {
  220.                 long                            Scan;
  221.                 long                            Limit;
  222.  
  223.                 Limit = ArrayGetLength(ListOfSelections);
  224.                 for (Scan = 0; Scan < Limit; Scan += 1)
  225.                     {
  226.                         AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  227.  
  228.                         AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  229.                             ListOfSelections,Scan);
  230.                         AlgoWaveTableObjectOpenWindow(AlgoWaveTableTemp);
  231.                     }
  232.                 DisposeArray(ListOfSelections);
  233.             }
  234.     }
  235.  
  236.  
  237. /* create a new algorithmic wave table and open a window for it */
  238. void                                AlgoWaveTableListNewAlgoWaveTable(AlgoWaveTableListRec* AlgoWaveTableList)
  239.     {
  240.         AlgoWaveTableObjectRec*    AlgoWaveTable;
  241.  
  242.         CheckPtrExistence(AlgoWaveTableList);
  243.         /* create the object */
  244.         AlgoWaveTable = NewAlgoWaveTableObject(AlgoWaveTableList->CodeCenter,
  245.             AlgoWaveTableList->MainWindow,AlgoWaveTableList);
  246.         if (AlgoWaveTable == NIL)
  247.             {
  248.              FailurePoint1:
  249.                 AlertHalt("There is not enough memory available to create a new algorithmic "
  250.                     "wave table.",NIL);
  251.                 return;
  252.             }
  253.         /* add it to the string list */
  254.         if (!InsertStringListElement(AlgoWaveTableList->List,NIL,NIL,AlgoWaveTable,True))
  255.             {
  256.              FailurePoint2:
  257.                 DisposeAlgoWaveTableObject(AlgoWaveTable);
  258.                 goto FailurePoint1;
  259.             }
  260.         MainWindowDeselectAllOtherStringLists(AlgoWaveTableList->MainWindow,AlgoWaveTableList);
  261.         SelectStringListElement(AlgoWaveTableList->List,AlgoWaveTable);
  262.         MakeStringListSelectionVisible(AlgoWaveTableList->List);
  263.         /* add it to the array */
  264.         if (!ArrayAppendElement(AlgoWaveTableList->AlgoWaveTableArray,AlgoWaveTable))
  265.             {
  266.              FailurePoint3:
  267.                 RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTable,True);
  268.                 goto FailurePoint2;
  269.             }
  270.         /* update our internal flags */
  271.         AlgoWaveTableList->AlgoWaveTableListChanged = True;
  272.         /* change the name in the list */
  273.         AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableList,AlgoWaveTable);
  274.         /* show the window */
  275.         AlgoWaveTableObjectOpenWindow(AlgoWaveTable);
  276.     }
  277.  
  278.  
  279. /* delete the selected algorithmic wave table */
  280. void                                AlgoWaveTableListDeleteSelection(AlgoWaveTableListRec* AlgoWaveTableList)
  281.     {
  282.         ArrayRec*                    ListOfSelections;
  283.  
  284.         CheckPtrExistence(AlgoWaveTableList);
  285.         ListOfSelections = GetListOfSelectedItems(AlgoWaveTableList->List);
  286.         if (ListOfSelections != NIL)
  287.             {
  288.                 long                                Scan;
  289.                 long                                Limit;
  290.  
  291.                 Limit = ArrayGetLength(ListOfSelections);
  292.                 for (Scan = 0; Scan < Limit; Scan += 1)
  293.                     {
  294.                         AlgoWaveTableObjectRec*    OneToZap;
  295.  
  296.                         OneToZap = (AlgoWaveTableObjectRec*)ArrayGetElement(ListOfSelections,Scan);
  297.                         AlgoWaveTableListDeleteAlgoWaveTable(AlgoWaveTableList,OneToZap);
  298.                     }
  299.                 DisposeArray(ListOfSelections);
  300.             }
  301.     }
  302.  
  303.  
  304. /* delete the explicitly specified algorithmic wave table */
  305. void                                AlgoWaveTableListDeleteAlgoWaveTable(AlgoWaveTableListRec* AlgoWaveTableList,
  306.                                             struct AlgoWaveTableObjectRec* TheAlgoWaveTable)
  307.     {
  308.         long                                Scan;
  309.         long                                Limit;
  310.  
  311.         CheckPtrExistence(AlgoWaveTableList);
  312.         MainWindowClearInstrObjects(AlgoWaveTableList->MainWindow);
  313.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  314.         for (Scan = 0; Scan < Limit; Scan += 1)
  315.             {
  316.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  317.  
  318.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  319.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  320.                 if (TheAlgoWaveTable == AlgoWaveTableTemp)
  321.                     {
  322.                         FileSpec*                    BackupFileWhere;
  323.                         FileType*                    BackupFile;
  324.                         MyBoolean                    Success = False;
  325.  
  326.                         BackupFileWhere = NewTempFileSpec(CODE4BYTES('?','?','?','?'),
  327.                             CODE4BYTES('?','?','?','?'));
  328.                         if (BackupFileWhere != NIL)
  329.                             {
  330.                                 if (OpenFile(BackupFileWhere,&BackupFile,eReadAndWrite))
  331.                                     {
  332.                                         BufferedOutputRec*    Output;
  333.  
  334.                                         Output = NewBufferedOutput(BackupFile);
  335.                                         if (Output != NIL)
  336.                                             {
  337.                                                 if (WriteBufferedOutput(Output,sizeof(MAGICSCRAPSTRING),
  338.                                                     MAGICSCRAPSTRING))
  339.                                                     {
  340.                                                         if (AlgoWaveTableObjectWriteDataOut(TheAlgoWaveTable,Output)
  341.                                                             == eFileLoadNoError)
  342.                                                             {
  343.                                                                 Success = True;
  344.                                                             }
  345.                                                     }
  346.                                                 if (!EndBufferedOutput(Output))
  347.                                                     {
  348.                                                         Success = False;
  349.                                                     }
  350.                                             }
  351.                                          else
  352.                                             {
  353.                                                 CloseFile(BackupFile);
  354.                                             }
  355.                                     }
  356.                                  else
  357.                                     {
  358.                                         DeleteFile(BackupFileWhere);
  359.                                         DisposeFileSpec(BackupFileWhere);
  360.                                     }
  361.                             }
  362.                         if (Success)
  363.                             {
  364.                                 MainWindowNewDeleteUndoInfo(AlgoWaveTableList->MainWindow,BackupFileWhere,
  365.                                     BackupFile);
  366.                                 DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  367.                                 RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp,True);
  368.                                 ArrayDeleteElement(AlgoWaveTableList->AlgoWaveTableArray,Scan);
  369.                                 AlgoWaveTableList->AlgoWaveTableListChanged = True;
  370.                             }
  371.                          else
  372.                             {
  373.                                 YesNoCancelType        Decision;
  374.  
  375.                                 Decision = AskYesNoCancel("Unable to save undo information for object.  "
  376.                                     "Delete object anyway?",NIL,"Delete","Cancel",NIL/*nothirdbutton*/);
  377.                                 if (Decision == eYes)
  378.                                     {
  379.                                         DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  380.                                         RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp,True);
  381.                                         ArrayDeleteElement(AlgoWaveTableList->AlgoWaveTableArray,Scan);
  382.                                         AlgoWaveTableList->AlgoWaveTableListChanged = True;
  383.                                     }
  384.                             }
  385.                         return;
  386.                     }
  387.             }
  388.         EXECUTE(PRERR(AllowResume,"AlgoWaveTableListDeleteAlgoWaveTable:  couldn't find object"));
  389.     }
  390.  
  391.  
  392. /* the name of a algorithmic wave table has changed, so the name in the scrolling */
  393. /* list must also be changed */
  394. void                                AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableListRec* AlgoWaveTableList,
  395.                                             struct AlgoWaveTableObjectRec* TheAlgoWaveTable)
  396.     {
  397.         char*                            AlgoWaveTableName;
  398.  
  399.         CheckPtrExistence(AlgoWaveTableList);
  400.         CheckPtrExistence(TheAlgoWaveTable);
  401.         ERROR(ArrayFindElement(AlgoWaveTableList->AlgoWaveTableArray,TheAlgoWaveTable) < 0,
  402.             PRERR(ForceAbort,"AlgoWaveTableListAlgoWaveTableNameChanged:  unknown algowavetable"));
  403.         AlgoWaveTableName = AlgoWaveTableObjectGetNameCopy(TheAlgoWaveTable);
  404.         if (AlgoWaveTableName != NIL)
  405.             {
  406.                 char*                            AlgoWaveTableNameNullTerminated;
  407.  
  408.                 AlgoWaveTableNameNullTerminated = BlockToStringCopy(AlgoWaveTableName);
  409.                 if (AlgoWaveTableNameNullTerminated != NIL)
  410.                     {
  411.                         ChangeStringListElementName(AlgoWaveTableList->List,
  412.                             AlgoWaveTableNameNullTerminated,TheAlgoWaveTable);
  413.                         ReleasePtr(AlgoWaveTableNameNullTerminated);
  414.                     }
  415.                 ReleasePtr(AlgoWaveTableName);
  416.             }
  417.     }
  418.  
  419.  
  420. /* look for a specified algorithmic wave table.  returns NIL if not found.  the name is */
  421. /* NOT null terminated */
  422. struct AlgoWaveTableObjectRec*    AlgoWaveTableListLookupNamedAlgoWaveTable(
  423.                                             AlgoWaveTableListRec* AlgoWaveTableList, char* Name)
  424.     {
  425.         long                            Scan;
  426.         long                            Limit;
  427.  
  428.         CheckPtrExistence(AlgoWaveTableList);
  429.         CheckPtrExistence(Name);
  430.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  431.         for (Scan = 0; Scan < Limit; Scan += 1)
  432.             {
  433.                 AlgoWaveTableObjectRec*    AlgoWaveTable;
  434.                 char*                                        NameCopy;
  435.  
  436.                 AlgoWaveTable = (AlgoWaveTableObjectRec*)ArrayGetElement(
  437.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  438.                 NameCopy = AlgoWaveTableObjectGetNameCopy(AlgoWaveTable);
  439.                 if (NameCopy != NIL)
  440.                     {
  441.                         if (PtrSize(Name) == PtrSize(NameCopy))
  442.                             {
  443.                                 if (MemEqu(Name,NameCopy,PtrSize(Name)))
  444.                                     {
  445.                                         ReleasePtr(NameCopy);
  446.                                         return AlgoWaveTable;
  447.                                     }
  448.                             }
  449.                         ReleasePtr(NameCopy);
  450.                     }
  451.             }
  452.         return NIL;
  453.     }
  454.  
  455.  
  456. /* remove all data arrays for all algorithmic wave tables */
  457. void                                AlgoWaveTableListUnbuildAll(AlgoWaveTableListRec* AlgoWaveTableList)
  458.     {
  459.         long                            Scan;
  460.         long                            Limit;
  461.  
  462.         CheckPtrExistence(AlgoWaveTableList);
  463.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  464.         for (Scan = 0; Scan < Limit; Scan += 1)
  465.             {
  466.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  467.  
  468.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  469.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  470.                 AlgoWaveTableObjectUnbuild(AlgoWaveTableTemp);
  471.             }
  472.     }
  473.  
  474.  
  475. /* build all algorithmic wave tables.  returns True if successful. */
  476. MyBoolean                        AlgoWaveTableListMakeUpToDate(AlgoWaveTableListRec* AlgoWaveTableList)
  477.     {
  478.         long                            Scan;
  479.         long                            Limit;
  480.  
  481.         CheckPtrExistence(AlgoWaveTableList);
  482.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  483.         for (Scan = 0; Scan < Limit; Scan += 1)
  484.             {
  485.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  486.  
  487.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  488.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  489.                 if (!AlgoWaveTableObjectMakeUpToDate(AlgoWaveTableTemp))
  490.                     {
  491.                         return False;
  492.                     }
  493.             }
  494.         return True;
  495.     }
  496.  
  497.  
  498. /* the document's name has changed, so we need to update the windows */
  499. void                                AlgoWaveTableListGlobalNameChange(AlgoWaveTableListRec*
  500.                                             AlgoWaveTableList, char* NewFilename)
  501.     {
  502.         long                            Scan;
  503.         long                            Limit;
  504.  
  505.         CheckPtrExistence(AlgoWaveTableList);
  506.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  507.         for (Scan = 0; Scan < Limit; Scan += 1)
  508.             {
  509.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  510.  
  511.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  512.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  513.                 AlgoWaveTableObjectGlobalNameChange(AlgoWaveTableTemp,NewFilename);
  514.             }
  515.     }
  516.  
  517.  
  518. /*   4-byte little endian number of algorithmic wave table objects (positive 2s complement) */
  519. /*   n-byte data for all the algorithmic wave table objects */
  520.  
  521.  
  522. /* read algorithmic wave table objects from a file.  returns True if successful. */
  523. FileLoadingErrors        AlgoWaveTableListReadData(AlgoWaveTableListRec* AlgoWaveTableList,
  524.                                             struct BufferedInputRec* Input)
  525.     {
  526.         signed long                NumberOfObjects;
  527.         long                            Scan;
  528.  
  529.         CheckPtrExistence(AlgoWaveTableList);
  530.         CheckPtrExistence(Input);
  531.  
  532.         /*   4-byte little endian number of objects (positive 2s complement) */
  533.         if (!ReadBufferedSignedLongLittleEndian(Input,&NumberOfObjects))
  534.             {
  535.                 return eFileLoadDiskError;
  536.             }
  537.         if (NumberOfObjects < 0)
  538.             {
  539.                 return eFileLoadBadFormat;
  540.             }
  541.  
  542.         /*   n-byte data for all the objects */
  543.         for (Scan = 0; Scan < NumberOfObjects; Scan += 1)
  544.             {
  545.                 AlgoWaveTableObjectRec*    AlgoWaveTable EXECUTE(= (AlgoWaveTableObjectRec*)0x81818181);
  546.                 FileLoadingErrors                Error;
  547.  
  548.                 /* load the object */
  549.                 Error = AlgoWaveTableObjectNewFromFile(&AlgoWaveTable,Input,
  550.                     AlgoWaveTableList->CodeCenter,AlgoWaveTableList->MainWindow,AlgoWaveTableList);
  551.                 if (Error != eFileLoadNoError)
  552.                     {
  553.                      FailurePoint1:
  554.                         return Error;
  555.                     }
  556.                 CheckPtrExistence(AlgoWaveTable);
  557.                 /* add it to the string list */
  558.                 if (!InsertStringListElement(AlgoWaveTableList->List,NIL,NIL,AlgoWaveTable,True))
  559.                     {
  560.                      FailurePoint2:
  561.                         DisposeAlgoWaveTableObject(AlgoWaveTable);
  562.                         Error = eFileLoadOutOfMemory;
  563.                         goto FailurePoint1;
  564.                     }
  565.                 /* add it to the array */
  566.                 if (!ArrayAppendElement(AlgoWaveTableList->AlgoWaveTableArray,AlgoWaveTable))
  567.                     {
  568.                      FailurePoint3:
  569.                         RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTable,True);
  570.                         goto FailurePoint2;
  571.                     }
  572.                 /* change the name in the list */
  573.                 AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableList,AlgoWaveTable);
  574.             }
  575.  
  576.         return eFileLoadNoError;
  577.     }
  578.  
  579.  
  580. /* write algorithmic wave table objects to a file.  returns True if successful. */
  581. FileLoadingErrors        AlgoWaveTableListWriteData(AlgoWaveTableListRec* AlgoWaveTableList,
  582.                                             struct BufferedOutputRec* Output)
  583.     {
  584.         long                            NumberOfObjects;
  585.         long                            Scan;
  586.  
  587.         CheckPtrExistence(AlgoWaveTableList);
  588.         CheckPtrExistence(Output);
  589.  
  590.         /*   4-byte little endian number of objects (positive 2s complement) */
  591.         NumberOfObjects = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  592.         if (!WriteBufferedSignedLongLittleEndian(Output,NumberOfObjects))
  593.             {
  594.                 return eFileLoadDiskError;
  595.             }
  596.  
  597.         /*   n-byte data for all the objects */
  598.         for (Scan = 0; Scan < NumberOfObjects; Scan += 1)
  599.             {
  600.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  601.                 FileLoadingErrors                Error;
  602.  
  603.                 /* get the object */
  604.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  605.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  606.                 /* write the object out */
  607.                 Error = AlgoWaveTableObjectWriteDataOut(AlgoWaveTableTemp,Output);
  608.                 /* handle errors */
  609.                 if (Error != eFileLoadNoError)
  610.                     {
  611.                         return Error;
  612.                     }
  613.             }
  614.  
  615.         return eFileLoadNoError;
  616.     }
  617.  
  618.  
  619. /* after a file has been saved, this is called to mark all objects as not modified. */
  620. void                                AlgoWaveTableListMarkAllObjectsSaved(
  621.                                             AlgoWaveTableListRec* AlgoWaveTableList)
  622.     {
  623.         long                            Scan;
  624.         long                            Limit;
  625.  
  626.         CheckPtrExistence(AlgoWaveTableList);
  627.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  628.         for (Scan = 0; Scan < Limit; Scan += 1)
  629.             {
  630.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  631.  
  632.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  633.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  634.                 AlgoWaveTableObjectMarkAsSaved(AlgoWaveTableTemp);
  635.             }
  636.         AlgoWaveTableList->AlgoWaveTableListChanged = False;
  637.     }
  638.  
  639.  
  640. /* copy the selected object in the list to the clipboard.  return False if failed. */
  641. MyBoolean                        AlgoWaveTableListCopyObject(AlgoWaveTableListRec* AlgoWaveTableList)
  642.     {
  643.         ArrayRec*                            ListOfSelections;
  644.         MyBoolean                            TotalSuccessFlag = False;
  645.  
  646.         CheckPtrExistence(AlgoWaveTableList);
  647.         ListOfSelections = GetListOfSelectedItems(AlgoWaveTableList->List);
  648.         if (ListOfSelections != NIL)
  649.             {
  650.                 if (ArrayGetLength(ListOfSelections) >= 1)
  651.                     {
  652.                         AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  653.                         FileSpec*                        TempFileLocation;
  654.  
  655.                         AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  656.                             ListOfSelections,0);
  657.                         /* open the temporary file */
  658.                         TempFileLocation = NewTempFileSpec(CODE4BYTES('\?','\?','\?','\?'),
  659.                             CODE4BYTES('\?','\?','\?','\?'));
  660.                         if (TempFileLocation != NIL)
  661.                             {
  662.                                 FileType*                            FileDescriptor;
  663.  
  664.                                 if (OpenFile(TempFileLocation,&FileDescriptor,eReadAndWrite))
  665.                                     {
  666.                                         BufferedOutputRec*        BufferedFile;
  667.  
  668.                                         BufferedFile = NewBufferedOutput(FileDescriptor);
  669.                                         if (BufferedFile != NIL)
  670.                                             {
  671.                                                 MyBoolean                            WriteSucceeded = False;
  672.  
  673.                                                 if (WriteBufferedOutput(BufferedFile,sizeof(MAGICSCRAPSTRING),
  674.                                                     MAGICSCRAPSTRING))
  675.                                                     {
  676.                                                         if (AlgoWaveTableObjectWriteDataOut(AlgoWaveTableTemp,
  677.                                                             BufferedFile) == eFileLoadNoError)
  678.                                                             {
  679.                                                                 WriteSucceeded = True;
  680.                                                             }
  681.                                                     }
  682.                                                 if (EndBufferedOutput(BufferedFile) && WriteSucceeded)
  683.                                                     {
  684.                                                         char*                            Buffer;
  685.                                                         long                            NumberOfBytes;
  686.  
  687.                                                         NumberOfBytes = GetFileLength(FileDescriptor);
  688.                                                         Buffer = AllocPtrCanFail(NumberOfBytes,
  689.                                                             "AlgoWaveTableListCopyObject:  scrap buffer");
  690.                                                         if (Buffer != NIL)
  691.                                                             {
  692.                                                                 if (SetFilePosition(FileDescriptor,0))
  693.                                                                     {
  694.                                                                         if (0 == ReadFromFile(FileDescriptor,
  695.                                                                             Buffer,NumberOfBytes))
  696.                                                                             {
  697.                                                                                 if (SetScrapToThis(Buffer))
  698.                                                                                     {
  699.                                                                                         TotalSuccessFlag = True;
  700.                                                                                     }
  701.                                                                             }
  702.                                                                     }
  703.                                                                 ReleasePtr(Buffer);
  704.                                                             }
  705.                                                     }
  706.                                             }
  707.                                         CloseFile(FileDescriptor);
  708.                                     }
  709.                                 DeleteFile(TempFileLocation);
  710.                                 DisposeFileSpec(TempFileLocation);
  711.                             }
  712.                     }
  713.                 DisposeArray(ListOfSelections);
  714.             }
  715.         return TotalSuccessFlag;
  716.     }
  717.  
  718.  
  719. /* try to paste the clipboard in as an algorithmic wave table object.  returns False if */
  720. /* it failed or the clipboard did not contain an algorithmic wave table object. */
  721. MyBoolean                        AlgoWaveTableListPasteObject(AlgoWaveTableListRec* AlgoWaveTableList)
  722.     {
  723.         MyBoolean                    TotalSuccessFlag = False;
  724.         char*                            Scrap;
  725.  
  726.         CheckPtrExistence(AlgoWaveTableList);
  727.         Scrap = GetCopyOfScrap();
  728.         if (Scrap != NIL)
  729.             {
  730.                 FileSpec*                    TempFileLocation;
  731.  
  732.                 TempFileLocation = NewTempFileSpec(CODE4BYTES('\?','\?','\?','\?'),
  733.                     CODE4BYTES('\?','\?','\?','\?'));
  734.                 if (TempFileLocation != NIL)
  735.                     {
  736.                         FileType*                            FileDescriptor;
  737.  
  738.                         if (OpenFile(TempFileLocation,&FileDescriptor,eReadAndWrite))
  739.                             {
  740.                                 BufferedOutputRec*        BufferedFile;
  741.  
  742.                                 BufferedFile = NewBufferedOutput(FileDescriptor);
  743.                                 if (BufferedFile != NIL)
  744.                                     {
  745.                                         MyBoolean                            WriteSucceeded = False;
  746.  
  747.                                         if (WriteBufferedOutput(BufferedFile,PtrSize(Scrap),Scrap))
  748.                                             {
  749.                                                 WriteSucceeded = True;
  750.                                             }
  751.                                         if (EndBufferedOutput(BufferedFile) && WriteSucceeded)
  752.                                             {
  753.                                                 TotalSuccessFlag = AlgoWaveTableListPasteFromFile(
  754.                                                     AlgoWaveTableList,FileDescriptor);
  755.                                             }
  756.                                     }
  757.                                 CloseFile(FileDescriptor);
  758.                             }
  759.                         DeleteFile(TempFileLocation);
  760.                         DisposeFileSpec(TempFileLocation);
  761.                     }
  762.                 ReleasePtr(Scrap);
  763.             }
  764.         return TotalSuccessFlag;
  765.     }
  766.  
  767.  
  768. /* try to paste the algorithmic wave table object in from the file */
  769. MyBoolean                        AlgoWaveTableListPasteFromFile(AlgoWaveTableListRec* AlgoWaveTableList,
  770.                                             struct FileType* File)
  771.     {
  772.         MyBoolean                    TotalSuccessFlag = False;
  773.  
  774.         CheckPtrExistence(AlgoWaveTableList);
  775.         if (SetFilePosition(File,0))
  776.             {
  777.                 BufferedInputRec*    InputFile;
  778.  
  779.                 InputFile = NewBufferedInput(File);
  780.                 if (InputFile != NIL)
  781.                     {
  782.                         char                            HeaderTest[sizeof(MAGICSCRAPSTRING)];
  783.  
  784.                         if (ReadBufferedInput(InputFile,sizeof(MAGICSCRAPSTRING),HeaderTest))
  785.                             {
  786.                                 if (MemEqu(MAGICSCRAPSTRING,HeaderTest,sizeof(MAGICSCRAPSTRING)))
  787.                                     {
  788.                                         AlgoWaveTableObjectRec*        AlgoWaveTableTemp EXECUTE(= (AlgoWaveTableObjectRec*)0x81818181);
  789.  
  790.                                         if (eFileLoadNoError == AlgoWaveTableObjectNewFromFile(&AlgoWaveTableTemp,
  791.                                             InputFile,AlgoWaveTableList->CodeCenter,AlgoWaveTableList->MainWindow,
  792.                                             AlgoWaveTableList))
  793.                                             {
  794.                                                 CheckPtrExistence(AlgoWaveTableTemp);
  795.                                                 /* add it to the scrolling object list */
  796.                                                 if (!InsertStringListElement(AlgoWaveTableList->List,NIL,NIL,AlgoWaveTableTemp,True))
  797.                                                     {
  798.                                                      FailurePoint:
  799.                                                         DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  800.                                                     }
  801.                                                  else
  802.                                                     {
  803.                                                         MainWindowDeselectAllOtherStringLists(AlgoWaveTableList->MainWindow,
  804.                                                             AlgoWaveTableList);
  805.                                                         SelectStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp);
  806.                                                         MakeStringListSelectionVisible(AlgoWaveTableList->List);
  807.                                                         /* add it to the array */
  808.                                                         if (!ArrayAppendElement(AlgoWaveTableList->AlgoWaveTableArray,AlgoWaveTableTemp))
  809.                                                             {
  810.                                                                 RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp,True);
  811.                                                                 goto FailurePoint;
  812.                                                             }
  813.                                                          else
  814.                                                             {
  815.                                                                 /* change the name in the list */
  816.                                                                 AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableList,AlgoWaveTableTemp);
  817.                                                                 TotalSuccessFlag = True;
  818.                                                                 AlgoWaveTableList->AlgoWaveTableListChanged = True;
  819.                                                             }
  820.                                                     }
  821.                                             }
  822.                                     }
  823.                             }
  824.                         EndBufferedInput(InputFile);
  825.                     }
  826.             }
  827.         return TotalSuccessFlag;
  828.     }
  829.  
  830.  
  831. /* find out how many algorithmic wave tables there are in this list */
  832. long                                AlgoWaveTableListHowMany(AlgoWaveTableListRec* AlgoWaveTableList)
  833.     {
  834.         CheckPtrExistence(AlgoWaveTableList);
  835.         return ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  836.     }
  837.  
  838.  
  839. /* get an indexed algorithmic wave tables from the list */
  840. struct AlgoWaveTableObjectRec*    AlgoWaveTableListGetIndexedAlgoWaveTable(
  841.                                             AlgoWaveTableListRec* AlgoWaveTableList, long Index)
  842.     {
  843.         AlgoWaveTableObjectRec*    AlgoWaveTable;
  844.  
  845.         CheckPtrExistence(AlgoWaveTableList);
  846.         ERROR((Index < 0) || (Index >= AlgoWaveTableListHowMany(AlgoWaveTableList)),
  847.             PRERR(ForceAbort,"AlgoWaveTableListGetIndexedAlgoWaveTable:  index out of range"));
  848.         AlgoWaveTable = (AlgoWaveTableObjectRec*)ArrayGetElement(
  849.             AlgoWaveTableList->AlgoWaveTableArray,Index);
  850.         CheckPtrExistence(AlgoWaveTable);
  851.         return AlgoWaveTable;
  852.     }
  853.